package com.itheima.aspects;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @Author:篍
 * @Date: 2025/07/17 20:13
 * @Description:
 */

@Component
@Aspect //当前类为切面类
@Slf4j
public class RecordTimeAspect {
//    @Around("execution(* com.itheima.service.impl.DeptServiceImpl.*(..))")
//    public Object recordTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
//        long begin = System.currentTimeMillis();
//        //执行原始方法
//        Object result = proceedingJoinPoint.proceed();
//
//        long end = System.currentTimeMillis();
//        log.warn("执行耗时：{}毫秒",end-begin);
//        return result;
//    }

    @Around("execution(* com.itheima.service.impl.ReportServiceImpl.*(..))")
    public Object recordTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        long begin = System.currentTimeMillis();
        Object proceed = proceedingJoinPoint.proceed();
        long l = System.currentTimeMillis();
        log.warn("执行耗时：{}毫秒",l-begin);
        return proceed;
    }
}
